/**
 * 退款记录实体类 - 支付退款申请和处理状态的记录实体
 *
 * 开发人员：徐少洋
 * 开发时间：2025-10-25 至 2025-10-28
 * 模块职责：定义退款记录的基本信息和业务属性，支持退款申请的完整生命周期管理
 *
 * 技术要点：
 * - 多租户关联设计，与企业、支付订单实体关联
 * - 退款状态枚举管理，支持多种退款状态
 * - 金额精度控制，使用BigDecimal确保财务准确性
 * - 退款时间和响应信息记录
 * - JSON格式的响应数据存储
 *
 * 开发故事：负责退款记录实体的数据模型设计，与退款服务层深度配合，实现退款申请的完整生命周期管理和状态追踪。
 */
package com.pbl.entity;

import com.pbl.common.enums.RefundStatus;
import lombok.*;

import javax.persistence.*;
import java.math.BigDecimal;
import java.time.LocalDateTime;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Entity
@Table(name = "refund_records")
public class RefundRecord {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "enterprise_id", nullable = false)
    private Enterprise enterprise;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "payment_order_id", nullable = false)
    private PaymentOrder paymentOrder;

    @Column(name = "out_trade_no", nullable = false, length = 64)
    private String outTradeNo;

    @Column(name = "trade_no", length = 64)
    private String tradeNo;

    @Column(name = "refund_amount", nullable = false, precision = 12, scale = 2)
    private BigDecimal refundAmount;

    @Enumerated(EnumType.STRING)
    @Column(nullable = false, length = 16)
    private RefundStatus status;

    @Column(name = "requested_at")
    private LocalDateTime requestedAt;

    @Column(name = "refunded_at")
    private LocalDateTime refundedAt;

    @Lob
    @Column(name = "response")
    private String response; // JSON text

    @Column(name = "message", length = 255)
    private String message;

    @Column(name = "created_at", insertable = false, updatable = false)
    private LocalDateTime createdAt;

    @Column(name = "updated_at", insertable = false, updatable = false)
    private LocalDateTime updatedAt;
}
